Skip to content

perf(planner): plan a path whose name nothing reads as the unnamed pattern - #237

Merged
prrao87 merged 1 commit into
mainfrom
perf/named-path-inventory
Nov 28, 2026
Merged

prrao87 merged 1 commit into
mainfrom
perf/named-path-inventory

Conversation

@prrao87

@prrao87 prrao87 commented Nov 28, 2026

Copy link
Copy Markdown
Member

Part of #223.

Why

A named path is planned with PathMatch, which reads its label's node table in full, every column, into an inventory of nodes for building path values. It does that even when nothing reads the path. MATCH p = (c:Account {id: 1})-[:T*1..2]->(d) RETURN count(*) therefore read 20,000 accounts with their 500-byte notes, while the same pattern without p = read one row. In the shape suite's phrasing group, which writes one query eight equivalent ways, the named phrasings were 2.8 times slower than the unnamed ones in memory mode and 7.1 times slower in lazy mode, with 92 MiB peak memory against 2 MiB.

What changed

  • A path whose name nothing reads plans as the unnamed pattern. Before planning, the logical planner drops the name of each named path that appears nowhere else in its query. Each UNION branch is its own scope, and shortest paths keep their name. The path then gets the same plan as when written unnamed: the same start, the same hops, no PathMatch. A name that is read, or only passed along (WITH b, p RETURN count(b)), keeps PathMatch as before.
  • Finding reads is deliberately conservative. The check looks for the name among every string in the rest of the query, so a literal or property key equal to it (d.name = 'p') keeps the path named. That case plans exactly as before.
  • Equivalent phrasings are now tested to get one plan. test_plan_equivalence.py writes four queries several ways each (anchor inline or in WHERE, pattern written from either end, path named or unnamed) and checks that each query gets one physical plan and one answer, with Arrow tables and with Lance datasets.
  • Three tests that checked PathMatchExec: endpoints for unread paths now expect the unnamed plan, and the docs describe the rule (cypher.md, internals/operators.md, internals/optimizer.md).

One phrasing difference is left. When a query reads the path (RETURN length(p)), its anchor written in WHERE is pushed into the start scan (#225), but the WHERE also stays above PathMatch as a redundant filter, so that plan differs from the inline phrasing's by one FilterExec. Removing it means tracking which WHERE each pushed condition came from, so the new test leaves that case out. I've left the #223 item "Tests assert that equivalent phrasings of a query get the same plan" for you to judge.

Validation

  • cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings, make test (1,836 passed), make lint, the strict docs build and typos pass locally. CI has not run yet.
  • All three suites, per CONTRIBUTING.md: release wheels from main (93d7268) and this branch (9e9fdc2), alternating main and branch twice each, memory and lazy. Every answer check and every shape-suite phrasing and plan check passed.
  • Plans of every SF1 query are the same on both wheels (IC3 prints two inline properties in an order that changes between runs, as on main). No SF1 query has a named path other than a shortest path, so SF1 moves below are noise.

Shape suite headlines (small graph):

Group Headline Ideal memory: main memory: branch lazy: main lazy: branch
phrasing slowest / fastest of 8 phrasings 1 2.84x 1.03x 7.09x 1.03x
selectivity two filters: slowest / fastest end 1 14.44x 14.51x 11.83x 11.62x
selectivity hop order: slowest / fastest 1 1.56x 1.57x 1.46x 1.45x
count_rows slowest count / fastest rows <= 1 7.11x 7.12x 6.60x 6.52x
hubs cycle: degree 100000 / degree 10 1 0.99x 1.00x 1.01x 1.00x
hubs cycle, hub at both ends: degree 100000 / 10 1 3.80x 3.69x 2.95x 2.92x
hubs pattern predicate: degree 100000 / 10 1 1.00x 1.01x 1.01x 1.01x
hubs cycle at degree 100000: CSR / join <= 1 0.35x 0.35x 0.36x 0.36x
hubs predicate at degree 100000: CSR / join <= 1 0.05x 0.05x 0.10x 0.10x
optional filtered / unfiltered OPTIONAL MATCH <= 1 1.04x 1.02x 1.57x 1.56x
optional filtered OPTIONAL MATCH / filtered MATCH about 1 0.93x 0.91x 0.97x 0.97x
wide_columns cross_filter: notes / ids about 1 4.12x 4.15x 16.64x 16.99x
wide_columns top_k: notes / ids about 1 2.94x 2.93x 13.94x 13.94x
wide_columns far_filter: notes / ids about 1 1.39x 1.38x 6.53x 6.40x
wide_columns all: notes / ids > 1 4.34x 4.36x 16.69x 17.09x
early_exit LIMIT 10 / all rows, ids << 1 0.36x 0.36x 0.41x 0.41x
early_exit LIMIT 10 / all rows, notes << 1 0.65x 0.64x 0.85x 0.92x

Only the four named phrasings moved by 10% or more: 1.40–1.44 ms to 0.51–0.52 ms (−64%) in memory mode, 4.53–4.61 ms to 0.65–0.66 ms (−86%) in lazy mode, and peak memory 10.4 to 1.7 MiB and 92.5 to 2.1 MiB. The lazy early_exit notes headline moved because hop_limit_notes ran 7% slower; that query has no named path and the same plan on both wheels.

SF1 suites:

Suite Mode Geomean branch / main main run 2 / run 1
graph-benchmark memory 0.996 0.996
graph-benchmark-ldbc memory 1.002 1.067
graph-benchmark-ldbc lazy 1.000 1.003
graph-benchmark-ldbc-complex memory 0.994 0.987
graph-benchmark-ldbc-complex lazy 0.982 1.021

graph-benchmark-ldbc in memory mode was noisy: main's two runs differed by up to 21% on one query. q16 (+11%) and q30 (−12%) moved by 10% or more, both within that spread and with unchanged plans.

Machine: Apple M5 MacBook Pro, 24 GB, macOS 26.6.2. Load average about 10 when the run started, right after the release builds, and 3.1 to 7.8 later on; another terminal app was also running.

Every SF1 query

graph-benchmark, memory

Query main (ms) branch (ms) Change
query1 7.55 7.46 -1%
query2 12.32 12.24 -1%
query3 2.68 2.68 -0%
query4 1.60 1.60 +0%
query5 1.63 1.63 -0%
query6 1.90 1.89 -0%
query7 3.60 3.58 -1%
query8 12.94 12.93 -0%
query9 12.42 12.41 -0%

Geomean branch/main: 0.996; main run 2 / run 1: 0.996 (largest single-query main gap 2%)

graph-benchmark-ldbc, memory

Query main (ms) branch (ms) Change
query1 0.67 0.67 -0%
query2 0.58 0.58 +1%
query3 0.67 0.68 +1%
query4 0.53 0.53 +1%
query5 0.82 0.84 +3%
query6 0.47 0.48 +1%
query7 1.09 1.11 +2%
query8 0.66 0.67 +2%
query9 0.86 0.87 +2%
query10 0.77 0.76 -0%
query11 1.67 1.57 -6%
query12 0.80 0.78 -3%
query13 0.84 0.83 -2%
query14 0.56 0.56 +1%
query15 0.59 0.64 +8%
query16 0.71 0.79 +11%
query17 0.95 0.94 -0%
query18 0.76 0.74 -2%
query19 1.03 1.02 -1%
query20 2.27 2.17 -5%
query21 0.79 0.79 +0%
query22 0.75 0.74 -1%
query23 0.77 0.79 +2%
query24 0.73 0.74 +2%
query25 0.84 0.84 +1%
query26 0.77 0.81 +5%
query27 0.92 0.97 +5%
query28 1.50 1.46 -3%
query29 0.77 0.73 -6%
query30 22.25 19.62 -12%

Geomean branch/main: 1.002; main run 2 / run 1: 1.067 (largest single-query main gap 21%)

graph-benchmark-ldbc, lazy

Query main (ms) branch (ms) Change
query1 1.15 1.16 +1%
query2 1.41 1.42 +1%
query3 0.82 0.82 +0%
query4 0.80 0.81 +1%
query5 2.16 2.16 +0%
query6 0.75 0.75 +1%
query7 1.12 1.13 +0%
query8 1.76 1.74 -1%
query9 1.36 1.35 -0%
query10 0.95 0.96 +1%
query11 1.97 1.98 +0%
query12 6.54 6.63 +1%
query13 1.06 1.07 +2%
query14 0.72 0.71 -1%
query15 0.79 0.79 -1%
query16 1.14 1.13 -2%
query17 1.43 1.41 -1%
query18 1.18 1.16 -2%
query19 1.40 1.37 -2%
query20 16.60 16.63 +0%
query21 0.86 0.85 -0%
query22 0.96 0.96 -0%
query23 1.26 1.26 +0%
query24 1.09 1.09 +1%
query25 1.22 1.22 +1%
query26 1.09 1.09 +1%
query27 1.33 1.33 +0%
query28 2.03 2.04 +1%
query29 1.05 1.05 +1%
query30 19.92 19.75 -1%

Geomean branch/main: 1.000; main run 2 / run 1: 1.003 (largest single-query main gap 4%)

graph-benchmark-ldbc-complex, memory

Query main (ms) branch (ms) Change
query1 25.03 25.63 +2%
query2 2.60 2.54 -3%
query3 25.49 25.27 -1%
query4 5.83 5.82 -0%
query5 75.36 71.53 -5%
query6 20.80 20.85 +0%
query7 9.90 9.84 -1%
query8 2.38 2.38 -0%
query9 37.41 36.97 -1%
query10 18.27 18.28 +0%
query11 3.02 3.01 -0%
query12 16.25 16.33 +0%
query13 1.15 1.15 -0%
query14 247.16 245.94 -0%

Geomean branch/main: 0.994; main run 2 / run 1: 0.987 (largest single-query main gap 8%)

graph-benchmark-ldbc-complex, lazy

Query main (ms) branch (ms) Change
query1 35.64 34.97 -2%
query2 26.74 24.79 -7%
query3 169.87 169.96 +0%
query4 13.32 12.89 -3%
query5 97.71 95.38 -2%
query6 22.96 22.45 -2%
query7 13.75 13.59 -1%
query8 3.38 3.35 -1%
query9 228.07 218.30 -4%
query10 26.74 26.75 +0%
query11 5.37 5.35 -0%
query12 19.16 19.10 -0%
query13 1.42 1.41 -1%
query14 256.94 257.69 +0%

Geomean branch/main: 0.982; main run 2 / run 1: 1.021 (largest single-query main gap 6%)

🤖 Generated with Claude Code

…ttern

A named path reads its label's node table in full into PathMatch, even
when the query only counts paths or returns their ends. When the name
appears nowhere else in its query, drop it before planning, so the path
gets the plan it would get unnamed. Add a test that equivalent phrasings
of a query get one physical plan and one answer.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9e9fdc2
Status: ✅  Deploy successful!
Preview URL: https://ffe959f4.lance-csr.pages.dev
Branch Preview URL: https://perf-named-path-inventory.lance-csr.pages.dev

View logs

@prrao87
prrao87 merged commit 0d31528 into main Nov 28, 2026
10 checks passed
@prrao87
prrao87 deleted the perf/named-path-inventory branch November 28, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant